package com.sxt.study.luckymoney.service.impl;

import com.sxt.study.luckymoney.model.LuckyMoney;
import com.sxt.study.luckymoney.repository.LuckyMoneyRepository;
import com.sxt.study.luckymoney.service.LuckyMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author songj
 * @date 2019/7/23 18:35
 */
@Service
public class LuckyMoneyServiceImpl implements LuckyMoneyService {

    @Autowired
    private LuckyMoneyRepository luckyMoneyRepository;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean sendTwo(String sender, BigDecimal amount520, BigDecimal amount1314) {
        LuckyMoney luckyMoney520 = new LuckyMoney(amount520, sender);
        luckyMoneyRepository.save(luckyMoney520);
        int i = 1 / 0;
        LuckyMoney luckyMoney1314 = new LuckyMoney(amount1314, sender);
        luckyMoneyRepository.save(luckyMoney1314);
        return true;
    }
}
